package com.ruoyi.web.controller.jwtTest;

import com.ruoyi.common.constant.Constants;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class Test {

    public static void main(String[] args) {
        // 令牌自定义标识
        String header = "Authorization";

        // 令牌秘钥
        String secret = "abcdefghijklmnopqrstuvwxyz";

        // 令牌有效期（默认30分钟）
        int expireTime = 24*60*60*1000;

        Ca ca = new Ca();
        ca.setName("张三");
        ca.setPhonenumber("15343455623");

        Map<String,Object> claims = new HashMap<>();
        claims.put(Constants.LOGIN_USER_KEY,ca);

        String token = Jwts.builder()
                .setClaims(claims)
                .setExpiration(new Date(System.currentTimeMillis()+expireTime))
                .signWith(SignatureAlgorithm.HS512, secret).compact();
        System.out.println(token);
    }

}
